package com.wuyan.locationdog.viewmodel

import androidx.lifecycle.MutableLiveData
import com.arcsoft.commonbase.base.BaseViewModel
import com.arcsoft.commonbase.bean.BannerBean
import com.arcsoft.commonbase.bean.FileUploadBean
import com.arcsoft.commonbase.bean.MyInfoBean
import com.arcsoft.commonbase.bean.OrderListBean
import com.arcsoft.commonbase.bean.OrderListDetailBean
import com.arcsoft.commonbase.bean.ServiceDetail
import com.arcsoft.commonbase.bean.ServiceListBean
import com.arcsoft.commonbase.bean.ShareUrlBean
import com.arcsoft.commonbase.bean.VersionBean
import com.arcsoft.commonbase.bean.WorkOrderBean
import com.arcsoft.commonbase.bean.WorkOrderBeanDetail
import com.arcsoft.commonbase.net.RetrofitManager
import com.wuyan.locationdog.help.LoginHelp
import okhttp3.MultipartBody
import okhttp3.RequestBody

class MyViewModel : BaseViewModel() {


    val myInfoBean = MutableLiveData<MyInfoBean>()
    val anyBean = MutableLiveData<Any>()
    val getBannerBean = MutableLiveData<BannerBean>()
    val fileUploadBean = MutableLiveData<FileUploadBean>()
    val workOrderBean = MutableLiveData<WorkOrderBean>()
    val workOrderBeanDetail = MutableLiveData<WorkOrderBeanDetail>()
    val serviceDetail = MutableLiveData<ServiceDetail>()
    val orderListBean = MutableLiveData<OrderListBean>()
    val orderListDetailBean = MutableLiveData<OrderListDetailBean>()
    val error = MutableLiveData<Exception>()
    val success = MutableLiveData<Any>()
    val shareUrlBean = MutableLiveData<ShareUrlBean>()
    val versionBean = MutableLiveData<VersionBean>()




    fun getVersion(map: HashMap<String, Any>) {
        launch(block = {
            versionBean.value = RetrofitManager.apiService.getVersion(map).apiData()
        })
    }

    fun getMyInfo(map: HashMap<String, Any>) {
        launch(block = {
            myInfoBean.value = RetrofitManager.apiService.getMyInfo(map).apiData()
            LoginHelp.myInfoBean = myInfoBean.value!!
        }, error = {
            error.value = it
        })
    }
    fun getBanner(map: HashMap<String, Any>) {
        launch(block = {
            getBannerBean.value = RetrofitManager.apiService.getBanner(map).apiData()
        })
    }
    fun getCode(map: HashMap<String, Any>) {
        launch(block = {
            anyBean.value = RetrofitManager.apiService.getCode(map).apiData()
        })
    }
    fun updatePwd(map: HashMap<String, Any>) {
        launch(block = {
            anyBean.value = RetrofitManager.apiService.updatePwd(map).apiData()
        })
    }
    fun updatePwdByPhone(map: HashMap<String, Any>) {
        launch(block = {
            anyBean.value = RetrofitManager.apiService.updatePwdByPhone(map).apiData()
        })
    }
    fun updateDevicePwd(map: HashMap<String, Any>) {
        launch(block = {
            anyBean.value = RetrofitManager.apiService.updateDevicePwd(map).apiData()
        })
    }
    fun updateDevicePwdByPhone(map: HashMap<String, Any>) {
        launch(block = {
            anyBean.value = RetrofitManager.apiService.updateDevicePwdByPhone(map).apiData()
        })
    }

    fun addWorkOrder(map: HashMap<String, Any>) {
        launch(block = {
            anyBean.value = RetrofitManager.apiService.addWorkOrder(map).apiData()
        })
    }

    fun submitWorkOrder(map: HashMap<String, Any>) {
        launch(block = {
            anyBean.value = RetrofitManager.apiService.submitWorkOrder(map).apiData()
        })
    }
    fun workOrderList(map: HashMap<String, Any>) {
        launch(block = {
            workOrderBean.value = RetrofitManager.apiService.workOrderList(map).apiData()
        })
    }
    fun workOrderDetail(map: HashMap<String, Any>) {
        launch(block = {
            workOrderBeanDetail.value = RetrofitManager.apiService.workOrderDetail(map).apiData()
        })
    }
    fun updateUserInfo(map: HashMap<String, Any>) {
        launch(block = {
            anyBean.value = RetrofitManager.apiService.updateUserInfo(map).apiData()
        })
    }
    fun fileUpload(map: HashMap<String, RequestBody>,file: MultipartBody.Part) {
        launch(block = {
            fileUploadBean.value = RetrofitManager.apiService.fileUpload(map,file).apiData()
        })
    }
    fun pay(map: HashMap<String, Any>) {
        launch(block = {
            success.value = RetrofitManager.apiService.pay(map).apiData()
        })
    }

    fun myOrderList(map: HashMap<String, Any>) {
        launch(block = {
            orderListBean.value = RetrofitManager.apiService.myOrderList(map).apiData()
        })
    }
    fun myOrderDetail(map: HashMap<String, Any>) {
        launch(block = {
            orderListDetailBean.value = RetrofitManager.apiService.myOrderDetail(map).apiData()
        })
    }

    fun serviceDetail(map: HashMap<String, Any>) {
        launch(block = {
            serviceDetail.value = RetrofitManager.apiService.serviceDetail(map).apiData()
        })
    }
    fun serviceRechargeDetail(map: HashMap<String, Any>) {
        launch(block = {
            serviceDetail.value = RetrofitManager.apiService.serviceRechargeDetail(map).apiData()
        })
    }

    fun serviceAdd(map: HashMap<String, Any>) {
        launch(block = {
            shareUrlBean.value = RetrofitManager.apiService.serviceAdd(map).apiData()
        })
    }
}